package com.pro.service.imple;

import com.pro.mapper.WelcomeMapper;
import com.pro.service.WelcomeService;
import com.pro.utils.DateUtil;
import org.apache.ibatis.annotations.MapKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.*;
import java.util.logging.Logger;

/**
 * ClassName:WelcomeServiceImple
 * Package:com.pro.service.imple
 * Description:
 *
 * @Date:2022/1/21 17:54
 * @Author: ZPT
 */
@Service
public class WelcomeServiceImple implements WelcomeService {
    @Autowired(required = false)
    private WelcomeMapper welcomeMapper;

    /**
     * @author ZPT
     * @date 2022/1/21 17:27
     * @content :上架商品总数 1
     */
    @Override
    public Integer getGoodsSum(Integer productSate) {
        return welcomeMapper.getGoodsSum(productSate);
    }

    /**
     * @author ZPT
     * @date 2022/1/21 17:27
     * @content :上传视频总数 2
     */
    @Override
    public Integer getCourseStatusSum(Integer courseStatus) {
        return welcomeMapper.getCourseStatusSum(courseStatus);
    }

    /**
     * @author ZPT
     * @date 2022/1/21 17:28
     * @content :发布微圈总数
     */
    @Override
    public Integer getMicrocircleSum() {
        return welcomeMapper.getMicrocircleSum();
    }

    /**
     * @author ZPT
     * @date 2022/1/21 17:28
     * @content :已完成订单总数 3 退订待审核量 7
     */
    @Override
    public Integer getOrderSum(Integer orderStatus) {
        return welcomeMapper.getOrderSum(orderStatus);
    }

    /**
     * @author ZPT
     * @date 2022/1/21 17:37
     * @content :商品、课程、微圈待审核量 2、待审核 2视频、3、商品 4、微圈
     */
    @Override
    public Integer getExamineSum(String result, Integer type) {
        return welcomeMapper.getExamineSum(result, type);
    }

    /**
     * @author ZPT
     * @date 2022/1/21 17:47
     * @content :今日新增用户
     */
    @Override
    public Integer getTodayUserSum() {
        return welcomeMapper.getTodayUserSum();
    }

    /**
     * @author ZPT
     * @date 2022/1/21 17:47
     * @content :昨日新增用户
     */
    @Override
    public Integer getYesterdayUserSum() {
        return welcomeMapper.getYesterdayUserSum();
    }

    /**
     * @author ZPT
     * @date 2022/1/21 17:47
     * @content :本月新增用户
     */
    @Override
    public Integer getMonthUserSum() {
        return welcomeMapper.getMonthUserSum();
    }

    /**
     * @author ZPT
     * @date 2022/1/22 18:23
     * @content :本月新增课程数量
     */
    @Override
    public Integer getCourseMonthAddCount() {
        return welcomeMapper.getCourseMonthAddCount();
    }

    /**
     * @author ZPT
     * @date 2022/1/22 18:24
     * @content :本周用户申请成功数量
     */
    @Override
    public Integer getUserAddWeekCount() {
        return welcomeMapper.getUserAddWeekCount();
    }

    /**
     * @author ZPT
     * @date 2022/1/22 18:40
     * @content :上一个月的新增课程数量
     */
    @Override
    public Integer getCourseAddLastMonthCount() {
        return welcomeMapper.getCourseAddLastMonthCount();
    }

    /**
     * @author ZPT
     * @date 2022/1/22 19:28
     * @content :上一个月的用户数量
     */
    @Override
    public Integer getUserAddLastMonthCount() {
        return welcomeMapper.getUserAddLastMonthCount();
    }

    /**
     * @author ZPT
     * @date 2022/1/23 21:04
     * @content :上传视频总数
     */
    @Override
    public Integer getCourseSum() {
        return welcomeMapper.getCourseSum();
    }

    /**
     * @author ZPT
     * @date 2022/1/23 20:44
     * @content :视频浏览、收藏、点赞量
     */
    @Override
    public Integer getCourseQuantitySum(String field, Integer courseStatus) {
        return welcomeMapper.getCourseQuantitySum(field, courseStatus);
    }

    /**
     * @author ZPT
     * @date 2022/1/23 21:12
     * @content :微圈点赞量
     */
    @Override
    public Integer getMicrocircleQuantitySum(String field) {
        return welcomeMapper.getMicrocircleQuantitySum(field);
    }

    /**
     * @author ZPT
     * @date 2022/1/21 18:34
     * @content :本周新增量
     */
    @Override
    public Map<String, Object> getWeekCount(String field, String table, String dataType) {
        Map<String, Object> map = new HashMap<>();
        //每个周
        List<String> weekList = DateUtil.getWeekOfMonth(new Date());
        //每个周内内的创建总数
        int[] weekData = new int[weekList.size()];
        //根据每周获取的创建数量
        Map<String, String> goodsWeekCount = welcomeMapper.getWeekCount(field, table, "%Y-%m-%d");
        for (int i = 0; i < weekList.size(); i++) {
            //根据key获取对应的val
            Object count = goodsWeekCount.get(weekList.get(i));
            if (count != null) {
                String value = String.valueOf(count);
                //截取每周内的创建总数
                String substring = value.substring(value.indexOf('=') + 1, value.indexOf(','));
                weekData[i] = Integer.parseInt(substring);
            }
        }
        map.put("data", weekData);
        map.put("list", weekList);
        return map;
    }

    /**
     * @author ZPT
     * @date 2022/1/24 18:39
     * @content :商品销售总量
     */
    @Override
    public Integer getGoodsSalesSum(Integer orderType, Integer productSate) {
        return welcomeMapper.getGoodsSalesSum(orderType, productSate);
    }

    /**
     * @author ZPT
     * @date 2022/1/24 18:39
     * @content :商品收藏总数
     */
    @Override
    public Integer getGoodsCollectSum(Integer collectionType) {
        return welcomeMapper.getGoodsCollectSum(collectionType);
    }

    /**
     * @author ZPT
     * @date 2022/1/24 19:13
     * @content :订单总数
     */
    @Override
    public Integer getOrderCount() {
        return welcomeMapper.getOrderCount();
    }

    /**
     * @author ZPT
     * @date 2022/1/24 19:18
     * @content :本月新增商品
     */
    @Override
    public Integer getGoodsMonthAddSum() {
        return welcomeMapper.getGoodsMonthAddSum();
    }

    /**
     * @author ZPT
     * @date 2022/1/24 19:18
     * @content :上个月新增商品
     */
    @Override
    public Integer getGoodsLastMonthAddSum() {
        return welcomeMapper.getGoodsLastMonthAddSum();
    }

    /**
     * @author ZPT
     * @date 2022/1/26 18:41
     * @content :前端用户总数
     */
    @Override
    public Integer getBeforeUserSum() {
        return welcomeMapper.getBeforeUserSum();
    }

    /**
     * @author ZPT
     * @date 2022/1/26 18:45
     * @content :进思用户总数
     */
    @Override
    public Integer getJinSiBeforeUserSum() {
        return welcomeMapper.getJinSiBeforeUserSum();
    }

    /**
     * @author ZPT
     * @date 2022/1/26 18:46
     * @content :非进思用户总数
     */
    @Override
    public Integer getNoJinSiBeforeUserSum() {
        return welcomeMapper.getNoJinSiBeforeUserSum();
    }

    /**
     * @author ZPT
     * @date 2022/1/26 19:04
     * @content :后台用户总数
     */
    @Override
    public Integer getUserSum() {
        return welcomeMapper.getUserSum();
    }

    /**
     * @author ZPT
     * @date 2022/1/26 19:12
     * @content :创作者认证待处理信息 1
     */
    @Override
    public Integer getPendingApplyRecordSum(Integer result) {
        return welcomeMapper.getPendingApplyRecordSum(result);
    }

    /**
     * @author ZPT
     * @date 2022/1/26 19:28
     * @content :上一个月的前端用户量
     */
    @Override
    public Integer getLastAddBeforeUserSum() {
        return welcomeMapper.getLastAddBeforeUserSum();
    }
}
